<?php
namespace app\common\traits\wechat;

use Thenbsp\Wechat\Wechat\AccessToken;

trait  WechatAccessToken
{
    use WechatCache;

    /**
     * 获取微信接口调用凭据（access_token）
     * @return mixed|null
     */
    protected function getAccessToken()
    {
        $appid = config('wechat.appid');
        $appsecret = config('wechat.appsecret');
        $accessToken = $this->getAccessTokenObject();
        return $accessToken->getTokenString();
    }

    protected function getAccessTokenObject()
    {
        $appid = config('wechat.appid');
        $appsecret = config('wechat.appsecret');
        $accessToken = new AccessToken($appid, $appsecret);
        $accessToken->setCache($this->wechatCacheDriver());
        return $accessToken;
    }
}